/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package api;

import cz.muni.restinterface.CourierDTO;
import org.codehaus.jackson.JsonNode;
import org.springframework.http.HttpEntity;

/**
 *
 * @author osiris
 */
public class RestClientCourierImpl extends RestClientAPI implements RestClientCourierInteface {
    
    public RestClientCourierImpl(String url) {
    
        super(url);
    }

    @Override
    public void create(CourierDTO courier) {
       HttpEntity<CourierDTO> entity = new HttpEntity<CourierDTO>(courier,headers);
        uri =  rt.postForLocation(url.concat("create"),entity);   
    }

    @Override
    public void delete(String id) {
        rt.delete(url.concat("delete=").concat(id)); 
    }

    @Override
    public void update(CourierDTO courier) {
        HttpEntity<CourierDTO> entity = new HttpEntity<CourierDTO>(courier,headers);
        rt.put(url.concat("update"),entity); 
    }

    @Override
    public void findall() {
         JsonNode jsonNode = rt.getForObject(url.concat("/findall"), JsonNode.class);
         for(JsonNode m : jsonNode) {
            System.out.println("entry = " + m);
        }
    }

    @Override
    public JsonNode findById(String id) {
        return rt.getForObject(url.concat("findbyid=").concat(id), JsonNode.class);
    }
    
    
    
}
